import { NavigationActions } from 'react-navigation'

const navigator = {
  navigateTo (route, params) {
    return NavigationActions.navigate({
      routeName: route,
      params
    })
  },
  resetRouteTo (route, params) {
    return NavigationActions.reset({
      index: 0,
      actions: [
        NavigationActions.navigate({routeName: route, params})
      ]
    })
  },
  resetActiveRouteTo (routeArray, activeIndex) {
    const actionsArray = []
    for (let i = 0; i < routeArray.length; i++) {
      actionsArray.push(NavigationActions.navigate({ routeName: routeArray[i] }))
    }
    const resetAction = NavigationActions.reset({
      index: activeIndex,
      actions: actionsArray
    })
    return resetAction
  },
  backTo (key) {
    return NavigationActions.back({key})
  },
  setParams (params, key) {
    const setParamsAction = NavigationActions.setParams({
      params,
      key
    })
    return setParamsAction
  }
}

export default navigator
